//----------------------------------------------------------------------------------------
// @Project Includes
#include "includes.h"

//----------------------------------------------------------------------------------------
// @Local Macro Define in the module

//----------------------------------------------------------------------------------------
// @Local Type defines in the module

//----------------------------------------------------------------------------------------
// @Global Variables define in the module

//----------------------------------------------------------------------------------------
// @Prototypes of functions in the module

//========================================================================================
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
		/* Configure the NVIC Preemption Priority Bits */
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
    /*定时器*/
	
		//drv_systick_init();
		drv_flash_init();
		drv_gpio_init();
		//System_Clock_Frequency_Update();	/*节省SIZE*/
		drv_usart_init();
		drv_can_init();
		drv_wdg_init();
		
		printf("\r\n=============== botloader version=%s=============\r\n",BOOTLOADER_VERSION);
		if (drv_upgrade_check()== true)
		{
				printf("need to update,start update...\r\n");
			  if (gstcOtaUpdata.ecu == 0x78)/*CAN升级*/
				{
						srv_j1939_generalResponse(0);
						gstcOtaUpdataInfo.u16fwCrc16 = 0; /* tuxin todo */
				}
				else
				{
						srv_cosm_writeOtaInfoAck();
				}
		}
		else
		{
				//printf("don't need to update\r\n");
				printf("start jump to app(0x%0x)....\r\n",DEVICE_MAIN_APP_ADDR);
				drv_jump_app();
				//printf("Bootloader jump failure!\r\n");
				//printf("wait reboot....\r\n");
		}
		
		while (1)
		{
				srv_cosm_receiveProcess();
				drv_wdg_feed();
				srv_can_task();
		}
}

/**
 * @brief Assert failed function by user.
 * @param file The name of the call that failed.
 * @param line The source line number of the call that failed.
 */
#ifdef USE_FULL_ASSERT
void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line)
{
    while (1)
    {
    }
}
#endif // USE_FULL_ASSERT

// =======================================================================================
// End of file.
// =======================================================================================
